<script>
    $().ready(function(){
        $('.txt_active2').change(function(){
            var active = $(this).val();
             var id = $(this).attr('id');             
             $.ajax({
                type : "GET",
                dataType : "json",
                url : "<?php echo base_url().'admin/photo/change_active_photo'?>",
                data : 'id=' + id + '&active=' + active,
                success : function(result){
                    alert(result.error);
                    return false;
                }
            });
        }); 
        $('#delete_all').click(function(){            
            $('input[type=checkbox]:checked').each(function(){
                var id = $(this).val();
                $.ajax({
                    type : "GET",
                    dataType : "html",
                    url : "<?php echo base_url().'admin/photo/ajax_delete_all_photo'?>",
                    data : "id=" + id,
                    success : function(request){
                        alert(request);
                        $('.check' + id).remove();
                        return false;
                    }
                    
                });
                
               
            });
            
        });
        
        
        $('#all').click(function(){
        if($(this).is(':checked'))
        {
            $('.check').attr('checked',true);
            var bien = $('.check').attr('checked',true);
            
        }
        else
        {
            $('.check').attr('checked',false);
        }
        
        
      });  

     });   
 </script> 
  
   
<table cellpadding="0" cellspacing="0" style="background:#FFF; color:#000;">
        <tr class="tr">
        	<td><input type="checkbox" class="all" id="all"/></td>    
            <td>Tên</td>    	
            <td>Hình ảnh</td>             
            <td>Sắp xếp</td>
            <td>Kích hoạt</td>           
            <td colspan="2">Hành động</td>            
        </tr>
        <?php foreach($photo as $row):?>
        <tr style="text-align:center">
        	<td><input type="checkbox" class="check" value="<?php echo $row->id_photo?>"/></td>   
            <td><?php echo $row->name_photo;?></td>
        	<td><img src="<?php echo base_url().$row->image;?>" style="width: 150px; height:150px;" /></td>
            <td><?php echo $row->order_photo;?></td>
            <td>
             <select class="txt_active2" id="<?php echo $row->id_photo;?>" style="width:120px">
            	<option value="1"<?php if($row->active == '1') echo "selected";?>>Hiển thị</option>
                <option value="0"<?php if($row->active == '0') echo "selected";?>>Không hiện thị</option>
            </select>
            </td>
            <td>
            	<a href="<?php echo base_url().'admin/photo/edit_photo/'.$row->id_photo;?>" title="Edit"><img src="<?php echo base_url()?>public/admin/images/user_edit.png"></a>
                &nbsp;&nbsp;&nbsp;<a href="<?php echo base_url().'admin/photo/delete_photo/'.$row->id_photo;?>" title="Delete"><img src="<?php echo base_url()?>public/admin/images/trash.png"></a>
            
            </td>
        </tr>
        <?php endforeach; ?>
      
        

</table>


